﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RiskMan.DataClass.Models;
using AvalonDock;
using RiskMan.DataClass.Models.Quik;

namespace RiskMan.Views.LimitStock
{
    public partial class LimitStockView : DocumentContent
    {

        public List<PositionModel> GetCount(List<EmitentLimitModel> list)
        {
            List<PositionModel> result = new List<PositionModel>();
            for (int i = 0; i < list.Count; i++)
            {
                // if ( list [ i ].CurrentOst != 0 )
                {
                    result.Add(new PositionModel()
                    {
                        Account = list[i].Account,
                        ClientCode = list[i].ClientCode,
                        Seccode = list[i].Seccode,
                        Count = list[i].CurrentOst / mainWindow._dataProvider.GetLots(list[i].Seccode),
                        Message = false
                    });
                }
            }
            return result;
        }

        private IEnumerable<PositionModel> GetCount(List<PositionToClientAccountModel> list)
        {
            List<PositionModel> result = new List<PositionModel>();
            for (int i = 0; i < list.Count; i++)
            {
                result.Add(new PositionModel()
                {
                    Account = list[i].Account,
                    ClientCode = list[i].Account,
                    Seccode = list[i].Seccode,
                    Count = list[i].CurrentEmptyPos
                });
            }
            return result;
        }

        public List<string> RunningClientCode ()
        {
            List<string> list= new List<string>();

            for (int i = 0; i < mainWindow._dataProvider.LimitStockList.Count; i++)
                if ( mainWindow._dataProvider.LimitStockList[i].IsRun == true)
                    list.Add(mainWindow._dataProvider.LimitStockList[i].ClientCode);

            return list;
        }

        public bool IsRun(PositionModel pm)
        {
            for (int i = 0; i < mainWindow._dataProvider.LimitStockList.Count; i++)
            {
                if (mainWindow._dataProvider.LimitStockList[i].Seccode == pm.Seccode &&
                     mainWindow._dataProvider.LimitStockList[i].Account == pm.Account &&
                     mainWindow._dataProvider.LimitStockList[i].ClientCode == pm.ClientCode &&
                     mainWindow._dataProvider.LimitStockList[i].IsRun == true)
                    return mainWindow._dataProvider.LimitStockList[i].IsRun;
            }
            return false;
        }


    }
}
